//
//  MainrControllerViewController.swift
//  weibo1
//
//  Created by apple on 15/12/15.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class MainrControllerViewController: UITabBarController {

    @objc private func composeBtnDidClick() {
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //通过KVC间接的给tabbar赋值
        let mainTabBar = MainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: UIControlEvents.TouchUpInside)

        addchildviewcontrollers()
    }

 //表示只能在本类中访问
    private func addchildviewcontrollers() {
        
        addchildviewcontrollerr(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addchildviewcontrollerr(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addchildviewcontrollerr(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addchildviewcontrollerr(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }

    
    func addchildviewcontrollerr(Vc:UIViewController,title: String,imageName: String) {
        
        //设置选中
        self.tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: Vc)
        
        Vc.title = title
        
        Vc.tabBarItem.image = UIImage(named: imageName)
//        
//        Vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        
//        Vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(nav)
        
    } 
}
